package com.yan.yjhTest.concurrency.thread.createThread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * 创建线程：实现Callable接口
 */
public class MyCallable implements Callable {

    @Override
    public Object call() throws Exception {
        System.out.println(Thread.currentThread().getName());
        return "ok";
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Callable mc = new MyCallable();
        FutureTask<String> ft = new FutureTask<>(mc);

        Thread t1 = new Thread(ft);

        t1.start();

        String result = ft.get();

        System.out.println(result);
    }

}
